// 线性结构 先进先出 FIFO  例子:排队

class Lx_queue {
    constructor() {
        this.items = [];
    }

    enqueue(element) {
        this.items.push(element);
    }

    dequeue() {
        return this.items.shift();
    }

    front() {
        return this.items[0];
    }

    isEmpty() {
        return !this.items.length;
    }

    size() {
        return this.items.length;
    }

    toString(tag = " ") {
        return this.items.reduce((pre, cur) => {
            return pre !== "" ? pre + tag + cur : cur;
        }, "");
    }
}

let queue = new Lx_queue();
queue.enqueue(1);
queue.enqueue(2);
// console.log(queue.toString());

//参与人数num    传的次数count
function game(count, num) {
    let queue = new Lx_queue();
    for (var i = 1; i < num + 1; i++) {
        queue.enqueue(i);
    }
    while (count > 0) {
        queue.enqueue(queue.dequeue());
        count--;
    }
    return queue.front();
}

console.log(game(15, 20));

module.exports = Lx_queue;
